using System;
using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using Me.Prettyprint.Cassandra.Service;

namespace Me.Prettyprint.Cassandra.Connection
{
	public class ConnectionManagerListenersHandler
	{
		private Dictionary<string, ConnectionManagerListener> listeners = new Dictionary<string, ConnectionManagerListener>();
		
		public void Add(string listenerName, ConnectionManagerListener listener)
		{
			listeners.Add(listenerName, listener);
		}
		public void Remove(string listenerName)
		{
			listeners.Remove(listenerName);
		}
		public void Clear()
		{
			listeners.Clear();
		}
		public void FireOnHostDown(CassandraHost cassandraHost)
		{
			foreach (ConnectionManagerListener listener in listeners.Values)
			{
				listener.OnHostDown(cassandraHost);
			}
		}
		public void FireOnHostRestored(CassandraHost cassandraHost)
		{
			foreach (ConnectionManagerListener listener in listeners.Values)
			{
				listener.OnHostRestored(cassandraHost);
			}
		}
		public void FireOnAllHostsDown()
		{
			foreach (ConnectionManagerListener listener in listeners.Values)
			{
				listener.OnAllHostsDown();
			}
		}
		public void FireOnSuspendHost(CassandraHost cassandraHost, bool removed)
		{
			foreach (ConnectionManagerListener listener in listeners.Values)
			{
				listener.OnSuspendHost(cassandraHost, removed);
			}
		}
		public void FireOnUnSuspendHost(CassandraHost cassandraHost, bool readded)
		{
			foreach (ConnectionManagerListener listener in listeners.Values)
			{
				listener.OnUnSuspendHost(cassandraHost, readded);
			}
		}
		public void FireOnAddHost(CassandraHost cassandraHost, bool added, string errorMessage, System.Exception e)
		{
			foreach (ConnectionManagerListener listener in listeners.Values)
			{
				listener.OnAddHost(cassandraHost, added, errorMessage, e);
			}
		}
		public void FireOnRemoveHost(CassandraHost cassandraHost, bool removed, System.String message)
		{
			foreach (ConnectionManagerListener listener in listeners.Values)
			{
				listener.OnRemoveHost(cassandraHost, removed, message);
			}
		}
	}
}